export default {
  saveCartData(context, payload) {
    return new Promise((resolve, reject) => {
      // 1.查找原数组中是否添加过该商品
      let oldProduct = context.state.cartList.find(item => item.iid === payload.iid);
      // 2.判断oldProduct
      if(oldProduct) {
        context.commit('addCounter', oldProduct);
        resolve(`当前商品数量为${oldProduct.count}`);
      } else {
        context.commit('addToCart', payload);
        resolve("加入购物车成功");
      }
    });
  }
};